package com.spm.librarianmanagersystem.controller;

import com.alibaba.fastjson.JSONObject;
import com.spm.librarianmanagersystem.service.RegisterService;
import com.spm.librarianmanagersystem.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RegisterController {
    @Autowired
    private RegisterService rs;

    @PostMapping("/api/user/register")
    public JsonResult<String> register(@RequestBody JSONObject jsonObject){
        String token = rs.register(jsonObject);
        if(token == null){
            return new JsonResult<>(null,1,"注册失败");
        }
        return new JsonResult<>(token);
    }

    @PostMapping("/api/admin/user/add")
    public JsonResult<Boolean> addUser(@RequestBody JSONObject jsonObject){
        return new JsonResult<>(rs.addUser(jsonObject));
    }
}
